package com.cskaoyan.wordmemorize.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dao.entity.PermissionDO;
import com.cskaoyan.wordmemorize.dao.mapper.PermissionMapper;
import com.cskaoyan.wordmemorize.dto.admin.EmployeeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

// @RestController
public class EmployeeController {


    @Autowired
    PermissionMapper permissionMapper;

    @GetMapping("/admin/employee/info")
    public Result<EmployeeDTO> getUserInfo() {

        EmployeeDTO employeeDTO = new EmployeeDTO();
        employeeDTO.setId("1");
        employeeDTO.setName("xxx");


        LambdaQueryWrapper<PermissionDO> employeeDOWrapper = new LambdaQueryWrapper<>();
        employeeDOWrapper.select(PermissionDO::getPermissionCode);
        List<PermissionDO> permissionDOS
                = permissionMapper.selectList(employeeDOWrapper);
        List<String> permissions = permissionDOS.stream().map(PermissionDO::getPermissionCode).collect(Collectors.toList());


        employeeDTO.setPerms(permissions);
        return Result.ok(employeeDTO);
    }


}
